package com.ruoyi.hospital.hospitalized.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hospital.hospitalized.domain.THospitalized;
import com.ruoyi.hospital.hospitalized.service.ITHospitalizedService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 住院管理Controller
 *
 * @author Shawn
 * @date 2024-02-21
 */
@Controller
@RequestMapping("/hospital/hospitalized")
public class THospitalizedController extends BaseController {
    private String prefix = "hospital/hospitalized";

    @Autowired
    private ITHospitalizedService tHospitalizedService;

    @RequiresPermissions("hospital:hospitalized:view")
    @GetMapping()
    public String hospitalized() {
        return prefix + "/hospitalized";
    }

    /**
     * 查询住院管理列表
     */
    @RequiresPermissions("hospital:hospitalized:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(THospitalized tHospitalized) {
        startPage();
        tHospitalized.setAdmissionStatus("admission");
        List<THospitalized> list = tHospitalizedService.selectTHospitalizedList(tHospitalized);
        return getDataTable(list);
    }

    /**
     * 导出住院管理列表
     */
    @RequiresPermissions("hospital:hospitalized:export")
    @Log(title = "住院管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(THospitalized tHospitalized) {
        List<THospitalized> list = tHospitalizedService.selectTHospitalizedList(tHospitalized);
        ExcelUtil<THospitalized> util = new ExcelUtil<THospitalized>(THospitalized.class);
        return util.exportExcel(list, "住院管理数据");
    }

    /**
     * 新增住院管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存住院管理
     */
    @RequiresPermissions("hospital:hospitalized:add")
    @Log(title = "住院管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(THospitalized tHospitalized) {
        return toAjax(tHospitalizedService.insertTHospitalized(tHospitalized));
    }

    /**
     * 修改住院管理
     */
    @RequiresPermissions("hospital:hospitalized:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        THospitalized tHospitalized = tHospitalizedService.selectTHospitalizedById(id);
        mmap.put("tHospitalized", tHospitalized);
        return prefix + "/edit";
    }

    /**
     * 修改保存住院管理
     */
    @RequiresPermissions("hospital:hospitalized:edit")
    @Log(title = "住院管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(THospitalized tHospitalized) {
        return toAjax(tHospitalizedService.updateTHospitalized(tHospitalized));
    }

    /**
     * 删除住院管理
     */
    @RequiresPermissions("hospital:hospitalized:remove")
    @Log(title = "住院管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tHospitalizedService.deleteTHospitalizedByIds(ids));
    }

    @Log(title = "住院管理", businessType = BusinessType.OTHER)
    @PostMapping("/discharge")
    @ResponseBody
    public AjaxResult discharge(String ids) {
        return toAjax(tHospitalizedService.dischargeTHospitalizedByIds(ids));
    }
}
